/**
 * FileName: SSOSessionFactory Author:   zeroleavebaoyang Date:     2018/8/29 15:35 Description:
 */
package com.shiro.sso.demo.session;

import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SessionContext;
import org.apache.shiro.session.mgt.SessionFactory;
import org.apache.shiro.web.session.mgt.WebSessionContext;

public class SSOSessionFactory implements SessionFactory {

    @Override
    public Session createSession(SessionContext sessionContext) {
        SSOSession ssoSession = new SSOSession();
        if (null != sessionContext && sessionContext instanceof WebSessionContext) {
            WebSessionContext webSessionContext = (WebSessionContext) sessionContext;
            HttpServletRequest request = (HttpServletRequest) webSessionContext.getServletRequest();
            if (null != request) {
                ssoSession.setUserAgent(request.getHeader("User-Agent"));
            }
        }
        return ssoSession;
    }
}
